// ref: https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html
const AWS = require('aws-sdk');
const regions = require("../../common/awsRegions");
AWS.config.update({region: regions.region_ap_southeast_1});
const s3 = new AWS.S3({apiVersion: '2006-03-01'});

const d = {};

d.listBuckets = (params) => new Promise((resolve, reject) => {
  s3.listBuckets(params, function(err, data) {
    if (err) {
      reject(err);
    } // an error occurred
    else {
      resolve(data);
    }// successful response
  });
});

d.createBucket = (params) => new Promise((resolve, reject) => {
  s3.createBucket(params, function(err, data) {
    if (err) {
      reject(err);
    } // an error occurred
    else {
      resolve(data);
    }// successful response
  });
});

d.putObject = (params) => new Promise((resolve, reject) => {
  s3.putObject(params, function(err, data) {
    if (err) {
      reject(err);
    } // an error occurred
    else {
      resolve(data);
    }// successful response
  });
});

module.exports = d;
if (require.main === module) {
  (async () => {
    // const abc = await module.exports.getLayerVersionByArn({Arn: "arn:aws:lambda:us-east-2:599885534814:layer:pt-common-packages:3"});
    // console.log(abc);
  })();
}